package misp_backend.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.Data;
import misp_backend.domain.Order;
import misp_backend.domain.Payment;
import misp_backend.domain.Table;
import misp_backend.service.OrderService;
import misp_backend.service.PaymentService;
import misp_backend.mapper.PaymentMapper;
import misp_backend.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author yang
* @description 针对表【payment】的数据库操作Service实现
* @createDate 2025-05-17 21:55:01
*/
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment>
    implements PaymentService{
    @Autowired
    private TableService tableService;
    @Autowired
    private  OrderService orderService;
   public boolean makepayment(String ordernum){
       boolean result=false;
       QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
       queryWrapper.eq("order_num", ordernum);
       Order order=orderService.getOne(queryWrapper);
       Payment payment=new Payment();
       payment.setOrderNum(order.getOrderNum());
       payment.setTotalAmount(order.getTotalAmount());
       payment.setAlipayTraceNo(String.valueOf(IdUtil.getSnowflakeNextId()));
       Date date=new Date();
       payment.setCreateTime(date);
Table table=tableService.getById(order.getTableId());
table.setStatus("空闲");
table.setUpdateTime(date);
tableService.updateById(table);
order.setStatus("已支付");
order.setUpdateTime(date);
orderService.updateById(order);
result=this.save(payment);
return result;
    }
}




